import os
import get_img
import docx_retrieval
import picture_processing
from time import sleep

img_filepath = './screenshot.jpg'
docx_filepath = './dang_shi.docx'
the_docx_list = docx_retrieval.get_docx_lines(docx_filepath)  # 固化文件行内容，以便快速利用


def answers_show(answers: dict):
    """
    用于显示答案，另外接受一个flag，用来停滞
    当变剪切板变动时，用来显示更新后的答案
    :param flag: 剪切板变动时返回的flag
    :param answers:
    :return:
    """
    # 又重新写了个键盘监听用来清屏
    if len(answers) == 0:
        print('未查询到结果，请重试')
    else:
        for k, v in answers.items():
            print('{}\n{}'.format(k, v))
        print('_____________________分割线以上为结果_____________________')


while 1:
    flag = get_img.clipboard_get_img()  # 监控剪切板变换，会后台将图片保存下来
    if flag:
        os.system('cls')
        flag = False  # 使用后归为False
        bin_obj = picture_processing.get_img_file(img_filepath)
        lst = picture_processing.img_identification(bin_obj)
        answers = docx_retrieval._search(lst, the_docx_list)
        answers_show(answers)
        print('剪切板监控中。。。。。。')
    sleep(0.5)
